package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxDdYsy;
import cn.stylefeng.guns.modular.lx.mapper.LxDdYsyMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxDdYsyParam;
import cn.stylefeng.guns.modular.lx.model.result.LxDdYsyResult;
import  cn.stylefeng.guns.modular.lx.service.LxDdYsyService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 尹思莹
 * @since 2023-12-01
 */
@Service
public class LxDdYsyServiceImpl extends ServiceImpl<LxDdYsyMapper, LxDdYsy> implements LxDdYsyService {

    @Override
    public void add(LxDdYsyParam param){
        LxDdYsy entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxDdYsyParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxDdYsyParam param){
        LxDdYsy oldEntity = getOldEntity(param);
        LxDdYsy newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxDdYsyResult findBySpec(LxDdYsyParam param){
        return null;
    }

    @Override
    public List<LxDdYsyResult> findListBySpec(LxDdYsyParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxDdYsyParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(LxDdYsyParam param){
        return param.getDdId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxDdYsy getOldEntity(LxDdYsyParam param) {
        return this.getById(getKey(param));
    }

    private LxDdYsy getEntity(LxDdYsyParam param) {
        LxDdYsy entity = new LxDdYsy();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
